package com.example.chenjun.myapplication.mvp.model;

import com.example.chenjun.myapplication.mvp.BaseModel;
import com.example.chenjun.myapplication.net.NetController;
import com.example.chenjun.myapplication.net.NetUtil;
import com.example.chenjun.myapplication.net.netcallback.BaseCallback;

public class CookModel extends BaseModel {

    private static final String KEY = "972dade147376e219cb9a8dc6e2bfd26";

    public <T> void getCookLabel(BaseCallback<T> callback){
        new NetUtil<T>()
                .post()
                .setUrl("http://apis.juhe.cn/cook/category")
                .addParam("key", "972dade147376e219cb9a8dc6e2bfd26")
                .build()
                .enqueue(callback);
    }

    public <T> void getCookLabelDetail(String labelId, int index, int size, BaseCallback<T> callback){
        new NetUtil<T>()
                .post()
                .setUrl("http://apis.juhe.cn/cook/index")
                .addParam("key", "972dade147376e219cb9a8dc6e2bfd26")
                .addParam("cid", labelId)
                .addParam("pn", String.valueOf(index))
                .addParam("rn", String.valueOf(size))
                .build()
                .enqueue(callback);
    }

    public <T> void searchCookInfo(String searchKey, int index, int size, BaseCallback<T> callback){
        //http://apis.juhe.cn/cook/query.php
        new NetUtil<T>()
                .post()
                .setUrl("http://apis.juhe.cn/cook/query.php")
                .addParam("key", "972dade147376e219cb9a8dc6e2bfd26")
                .addParam("menu", searchKey)
                .addParam("pn", String.valueOf(index))
                .addParam("rn", String.valueOf(size))
                .build()
                .enqueue(callback);
    }

    public <T> void getCookDetail(String cookId, BaseCallback<T> callback){
        new NetUtil<T>()
                .post()
                .setUrl("http://apis.juhe.cn/cook/queryid")
                .addParam("key", "972dade147376e219cb9a8dc6e2bfd26")
                .addParam("id", cookId)
                .build()
                .enqueue(callback);
    }
}
